﻿using System;
using System.Collections.Generic;
using GameEditor.View.Components;
using PureMVC.Interfaces;
using PureMVC.Patterns;
using GameEngine.Model.Data;

namespace GameEditor.View
{
    public class ThingTypePropertiesEditor_MenuMediator<MyIdType> : Mediator
        where MyIdType : IComparable<MyIdType>
    {
        //public readonly String CREATEITEM_BUTTONPRESSED = "ItemEditorMenuMediator_CREATEITEM_";
        //public readonly String ADDITEM_BUTTONPRESSED = "ItemEditorMenuMediator_ADDITEM_";
        //public readonly String ADDSHAPE_BUTTONPRESSED = "ItemEditorMenuMediator_ADDSHAPE_";
        //public readonly String REMOVESHAPE_BUTTONPRESSED = "ItemEditorMenuMediator_REMOVESHAPE_";

        //IThingTypeDataProxy<ItemVOId> OnBuildThingType;

        public ThingTypePropertiesEditor_MenuMediator(String name, IThingTypeEditorMenuView<MyIdType> viewComponent)
            : base(name, viewComponent)
        {
            //CREATEITEM_BUTTONPRESSED += name;
            //ADDITEM_BUTTONPRESSED += name;
            //ADDSHAPE_BUTTONPRESSED += name;
            //REMOVESHAPE_BUTTONPRESSED += name;
        }

        public new IThingTypeEditorMenuView<MyIdType> ViewComponent
        {
            get { return base.ViewComponent as IThingTypeEditorMenuView<MyIdType>; }
        }

        public string ThingTypeName
        {
            get { return ViewComponent.ThingTypeName; }
            set { ViewComponent.ThingTypeName = value; }
        }

        public void AddType(string id) { ViewComponent.AddType(id); }
        public void RemoveType(string id) { ViewComponent.RemoveType(id); }
        public List<string> GetTypes() { return ViewComponent.GetTypes(); }
        public string SelectedType { get { return ViewComponent.SelectedType; } }

        public void AddView(IViewVOId<MyIdType> id) { ViewComponent.AddView(id); }
        public void RemoveView(IViewVOId<MyIdType> id) { ViewComponent.RemoveView(id); }
        public List<IViewVOId<MyIdType>> GetViews() { return ViewComponent.GetViews(); }
        public IViewVOId<MyIdType> SelectedView { get { return ViewComponent.SelectedView; } }


        #region IMediator Members

        /// <summary>
        /// List the <c>INotification</c> names this <c>Mediator</c> is interested in being notified of
        /// </summary>
        /// <returns>The list of <c>INotification</c> names </returns>
        override public IList<string> ListNotificationInterests()
        {
            return base.ListNotificationInterests();
        }

        /// <summary>
        /// Handle <c>INotification</c>s
        /// </summary>
        /// <param name="notification">The <c>INotification</c> instance to handle</param>
        /// <remarks>
        ///     <para>
        ///        Typically this will be handled in a switch statement, with one 'case' entry per <c>INotification</c> the <c>Mediator</c> is interested in. 
        ///     </para>
        /// </remarks>
        override public void HandleNotification(INotification notification)
        {
            base.HandleNotification(notification);
        }

        /// <summary>
        /// Called by the View when the Mediator is registered
        /// </summary>
        override public void OnRegister()
        {
            //ViewComponent.OnCreateClick += new Action<string>(ViewComponent_OnCreateItemClick);
            //ViewComponent.OnEditClick += new Action<string>(ViewComponent_OnEditClick);
            //ViewComponent.OnRemoveClick += new Action<string>(ViewComponent_OnRemoveClick);
            //ViewComponent.OnAddShapeClick += new Action<string, string, object>(ViewComponent_OnAddShapeClick);
            //ViewComponent.OnRemoveShapeClick += new Action<string, string>(ViewComponent_OnRemoveShapeClick);
            //ViewComponent.OnAddItemToWorldClick += new Action<string>(ViewComponent_OnAddItemClick);
            //ViewComponent.OnItemTypeClick += new Action<string>(ViewComponent_OnItemTypeClick);
            //ViewComponent.OnNewClick += new Action(ViewComponent_OnNewClick);
            base.OnRegister();
        }
        
        /// <summary>
        /// Called by the View when the Mediator is removed
        /// </summary>
        override public void OnRemove()
        {
            base.OnRemove();
        }

        #endregion

        //void ViewComponent_OnCreateItemClick(string obj)
        //{
        //    //SendNotification(CREATEITEM_BUTTONPRESSED, null, obj);
        //    //GameWorldProxy.ItemTypes.Add(new KeyValuePair<string, IThingTypeDataProxy<MyIdType>>(
        //    //    obj,
        //    //    OnBuildThingType));
        //    //ViewComponent.AddTypeToList(obj);
        //}

        //void ViewComponent_OnAddItemClick(string obj)
        //{
        //    //SendNotification(
        //    //    ADDITEMTOGAME_NOTIFICATION,
        //    //    ModelFacade<ItemVOId>.Instance.CreateItemDataProxy(
        //    //        GameWorldProxy.ItemTypes[obj]
        //    //    ),
        //    //    null);
        //    //SendNotification(ADDITEM_BUTTONPRESSED, null, obj);
        //    //WorldProxy.AddItem(
        //    //    ModelFacade<ItemVOId>.Instance.CreateItemDataProxy(
        //    //        WorldProxy.ItemTypes[obj]
        //    //    ));
        //}

        //void ViewComponent_OnAddShapeClick(string itemTypeName, string shapeType, object shapeProps)
        //{
        //    //SendNotification(ADDSHAPE_BUTTONPRESSED, arg2, arg1);
        //    //ThingViewShapeType ShapeType = new ThingViewShapeType(shapeType) { Properties = shapeProps };
        //    //IThingTypeViewShapeVO<MyIdType> shapeVO = ModelFacade<ItemVOId>.Instance.CreateItemViewShapeVO(ShapeType);

        //    //IThingTypeDataProxy<MyIdType> itemType;
        //    //if (GameWorldProxy.ItemTypes.ContainsKey(itemTypeName))
        //    //{
        //    //    itemType = GameWorldProxy.ItemTypes[itemTypeName];
        //    //}
        //    //else {
        //    //    if (OnBuildThingType == null || OnBuildThingType.Name != itemTypeName)
        //    //        OnBuildThingType = ModelFacade<ItemVOId>.Instance.CreateThingTypeDataProxy(itemTypeName);
        //    //    itemType = OnBuildThingType;
        //    //}
        //    //itemType.AddShape(shapeVO);
        //    ////Update shape menu
        //    //ViewComponent.AddShapeToList(ShapeType.Name + " - " + shapeVO.Id);

        //    //IThingDataProxy<MyIdType> item = ModelFacade<ItemVOId>.Instance.CreateItemDataProxy(itemType);

        //    //ItemEditorWorldMediator.proxy.RemoveAllItems();//TODO ver melhor maneira sem ser tirar tudo
        //    //item.Position = ItemEditorWorldMediator.proxy.Map.CameraPosition;
        //    //ItemEditorWorldMediator.proxy.AddItem(item);
        //}

        //void ViewComponent_OnRemoveShapeClick(string itemTypeName, string shapeName)
        //{
        //    //MyIdType id = ModelFacade<ItemVOId>.Instance.ParseId(shapeName.Split(" - ".ToCharArray())[1]);
        //    ////SendNotification(REMOVESHAPE_BUTTONPRESSED, arg2, arg1);
        //    //if (GameWorldProxy.ItemTypes.ContainsKey(itemTypeName))
        //    //{
        //    //    GameWorldProxy.ItemTypes[itemTypeName].RemoveShape(id);
        //    //}
        //    //else {
        //    //    if (OnBuildThingType == null || OnBuildThingType.Name != itemTypeName)
        //    //        OnBuildThingType = ModelFacade<ItemVOId>.Instance.CreateThingTypeDataProxy(itemTypeName);
        //    //    OnBuildThingType.RemoveShape(id);
        //    //}
            
        //    //ViewComponent.RemoveShapeFromList(shapeName);
        //}

        //void ViewComponent_OnRemoveClick(string obj)
        //{
        //    throw new NotImplementedException();
        //}

        //void ViewComponent_OnEditClick(string obj)
        //{
        //    throw new NotImplementedException();
        //}

        //void ViewComponent_OnNewClick()
        //{
        //    //ItemEditorWorldMediator.proxy.RemoveAllItems();
            
        //    //ViewComponent.RemoveAllShapesFromList();
        //}

        //void ViewComponent_OnItemTypeClick(string obj)
        //{
        //    //TODO adicionar type ao itemEditorWorldMediator 
        //    //IThingTypeDataProxy<MyIdType> itemType = GameWorldProxy.ItemTypes[obj];
        //    //ItemViewerWorldMediator.proxy.RemoveAllItems();
        //    //IThingDataProxy<MyIdType> item = ModelFacade<ItemVOId>.Instance.CreateItemDataProxy(itemType);
        //    //ItemViewerWorldMediator.proxy.AddItem(item);
        //}
    }
}